package cc.ycws.api.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import cc.ycws.core.domain.Visitorsuser1;
import cc.ycws.core.service.Visitorsuser1Service;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/ssm/visitorsuser")
public class Visitorsuser1Api {
    @Resource
    Visitorsuser1Service visitorsuserService;

    /**
     * 添加账号
     *
     * @param request
     * @param visitorsuser
     * @return
     */
    @ResponseBody
    @RequestMapping("/insert")
    public String insert(HttpServletRequest request, Visitorsuser1 visitorsuser) {
        String openid = request.getParameter("openid");
        visitorsuser.setOpenid(openid);
        int num = visitorsuserService.insert(visitorsuser);
        if (num == 1) {
            return "1";
        } else {
            return "0";
        }
    }

    @ResponseBody
    @RequestMapping("/select")
    public String select(HttpServletRequest request, ModelMap modelMap) {
        String openid = request.getParameter("openid");
        System.out.println("openid==" + openid);
        List<Visitorsuser1> list = visitorsuserService.select(openid);
        modelMap.addAttribute("list", list);
        JSONObject json = new JSONObject(modelMap);
        System.out.println(json.toString());
        return json.toString();
    }
}
